package com.qianfeng.smartmetting.config;

import com.alibaba.fastjson2.JSON;
import com.qianfeng.smartmetting.util.CommonResult;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

//注销成功
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse
            , Authentication authentication) throws IOException, ServletException {

        Map map = CommonResult.ok("注销成功",authentication.getPrincipal());

        String result = JSON.toJSONString(map);

        httpServletResponse.setContentType("application/json;charset=utf-8");

        httpServletResponse.getWriter().write(result);
    }
}
